﻿#region Header

/***************************************************************************
Author : Krishan Kaliraman (www.sharedwith.me)  Date: 1 Aug 2012
***************************************************************************/

#endregion Header
using System;
using System.Configuration;
using System.Net;

namespace Common
{
    public class ProxyWithCredentials : IWebProxy
    {
        public string Username { get; set; }
        public string Password { get; set; }
        private ICredentials credentials;

        public ProxyWithCredentials()
            : this(ConfigurationManager.AppSettings["ProxyUsername"], ConfigurationManager.AppSettings["ProxyPassword"])
        {

        }
        public ProxyWithCredentials(string username, string password)
        {
            this.Username = username;
            this.Password = password;
        }

        public ICredentials Credentials
        {
            get { return this.credentials ?? (this.credentials = new NetworkCredential(this.Username, this.Password)); }
            set { this.credentials = value; }
        }

        public Uri GetProxy(Uri destination)
        {
            return WebRequest.DefaultWebProxy.GetProxy(destination);
        }

        public bool IsBypassed(Uri host)
        {
            return WebRequest.DefaultWebProxy.IsBypassed(host);
        }
    }
}
